import { apiClient } from './apiClient';

// 认证相关接口
export interface LoginRequest {
  email: string;
  password: string;
}

export interface RegisterRequest {
  email: string;
  password: string;
  username?: string;
}

export interface TokenResponse {
  access_token: string;
  refresh_token: string;
  token_type: string;
  expires_in: number;
}

export interface UserInfo {
  user_id: number;
  username: string;
  email: string;
  is_superuser: boolean;
  is_active: boolean;
  roles?: string[];
  permissions?: string[];
  last_login_at?: string;
}

export interface ChangePasswordRequest {
  current_password: string;
  new_password: string;
}

export const authApi = {
  login: (data: LoginRequest): Promise<TokenResponse> =>
    apiClient.post('/auth/login', data),

  register: (data: RegisterRequest): Promise<UserInfo> =>
    apiClient.post('/auth/register', data),

  refreshToken: (refreshToken: string): Promise<TokenResponse> =>
    apiClient.post('/auth/refresh', { refresh_token: refreshToken }),

  getCurrentUser: (): Promise<UserInfo> =>
    apiClient.get('/auth/me'),

  changePassword: (data: ChangePasswordRequest): Promise<{ message: string }> =>
    apiClient.post('/auth/change-password', data),

  logout: (): Promise<{ message: string }> =>
    apiClient.post('/auth/logout'),
};